package Test;

class ListNode{
    int val;
    ListNode next;
    ListNode(int val){
        this.val=val;
    }
}

public class 删除排序链表中的重复元素II {
    public ListNode deleteDuplicates(ListNode head) {
        if(head==null||head.next==null){
            return head;
        }
        ListNode nxt=head.next;
        if(head.val==nxt.val){
            while (nxt!=null&&head.val==nxt.val){
                nxt=nxt.next;
            }
            head=deleteDuplicates(nxt);
        }else {
            head.next=deleteDuplicates(nxt);
        }
        return head;
    }
}
